from django.db import models
from common.models import BaseEnum
# Create your models here.


class AccountType(BaseEnum):
    EXPENSE = 'EXPENSE'
    BANK = 'BANK'
    EQUITY = 'EQUITY'
    ROOT = 'ROOT'
    INCOME = 'INCOME'
    ASSET = 'ASSET'
    LIABILITY = 'LIABILITY'
    CREDIT = 'CREDIT'
    CASH = 'CASH'


ACCOUNT_TYPE = AccountType.to_choices()


class Account(models.Model):
    guid = models.CharField(max_length=32, primary_key=True)
    name = models.CharField(max_length=2048)
    account_type = models.CharField(max_length=2048, choices=ACCOUNT_TYPE)
    commodity_guid = models.CharField(max_length=32, null=True)
    commodity_scu = models.IntegerField()
    parent_guid = models.CharField(max_length=32, null=True)
    code = models.CharField(max_length=2048, null=True)
    description = models.CharField(max_length=2048, null=True)
    hidden = models.IntegerField(null=True)
    placeholder = models.IntegerField(null=True)

    class Meta:
        db_table = 'accounts'


class Book(models.Model):
    guid = models.CharField(max_length=32, primary_key=True)
    root_account_guid = models.CharField(max_length=32)
    root_template_guid = models.CharField(max_length=32)

    class Meta:
        db_table = 'books'


class Commodity(models.Model):
    guid = models.CharField(max_length=32, primary_key=True)
    namespace = models.CharField(max_length=2048)
    mnemonic = models.CharField(max_length=2048)
    fullname = models.CharField(max_length=2048, null=True)
    cusip = models.CharField(max_length=2048, null=True)
    fraction = models.IntegerField()
    quote_flag = models.IntegerField()
    quote_source = models.CharField(max_length=2048, null=True)
    quote_tz = models.CharField(max_length=2048, null=True)

    class Meta:
        db_table = 'commodities'


class Slot(models.Model):
    obj_guid = models.CharField(max_length=32)
    name = models.CharField(max_length=4096)
    slot_type = models.IntegerField()
    int64_val = models.BigIntegerField(null=True)
    string_val = models.CharField(max_length=4096, null=True)
    double_val = models.FloatField(null=True)
    timespec_val = models.DateTimeField(null=True)
    guid_val = models.CharField(max_length=32, null=True)
    numeric_val_num = models.BigIntegerField(null=True)
    numeric_val_denom = models.BigIntegerField(null=True)
    gdate_val = models.DateField(null=True)

    class Meta:
        db_table = 'slots'


class Split(models.Model):
    guid = models.CharField(max_length=32, primary_key=True)
    tx_guid = models.CharField(max_length=32)
    account_guid = models.CharField(max_length=32)
    memo = models.CharField(max_length=2048)
    action = models.CharField(max_length=2048)
    reconcile_state = models.CharField(max_length=1)
    reconcile_date = models.DateTimeField(null=True)
    value_num = models.BigIntegerField()
    value_denom = models.BigIntegerField()
    quantity_num = models.BigIntegerField()
    quantity_denom = models.BigIntegerField()
    lot_guid = models.CharField(max_length=32, null=True)

    class Meta:
        db_table = 'splits'


class Transaction(models.Model):
    guid = models.CharField(max_length=32, primary_key=True)
    currency_guid = models.CharField(max_length=32)
    num = models.CharField(max_length=2048)
    post_date = models.DateTimeField(null=True)
    enter_date = models.DateTimeField(null=True)
    description = models.CharField(max_length=2048, null=True)

    class Meta:
        db_table = 'transactions'
